﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using ConciseMarkupLanguage.Utils;

namespace ConciseMarkupLanguage.Tags
{
    public class Media
    {
        [TemplateTag]
        public static string youtube(AttrDict attrs, string content)
        {
            return Html.Tag("iframe", new AttrDict {
                    {"title", "Youtube video player"},
                    {"width", 640},
                    {"height", 390},
                    {"src", !content.Contains('/') ? "http://www.youtube.com/embed/" + content : content},
                    {"frameborder", 0},
                    {"allowfullscreen", null},
                }.Merge(attrs), "");
        }

        [TemplateTag]
        public static string include_css(AttrDict attrs, string content)
        {
            return Html.Tag("link", new AttrDict {
                    {"rel", "stylesheet"},
                    {"type", "text/css"},
                    {"href", content},
                }.Merge(attrs), null);
        }

        [TemplateTag]
        public static string include_js(AttrDict attrs, string content)
        {
            return Html.Tag("script", new AttrDict {
                    {"type", "text/javascript"},
                    {"src", content},
                }.Merge(attrs), "");
        }

        [TemplateTag]
        public static string include_less(AttrDict attrs, string content)
        {
            return Html.Tag("link", new AttrDict {
                    {"rel", "stylesheet/less"},
                    {"type", "text/css"},
                    {"href", content},
                }.Merge(attrs), null);
        }

        [TemplateTag]
        public static string include(AttrDict attrs, string content)
        {
            string ext = Path.GetExtension(content);
            switch (ext.ToLower())
            {
                case ".css":
                    return include_css(attrs, content);
                case ".less":
                    return include_less(attrs, content);
                case ".js":
                    return include_js(attrs, content);
                default:
                    throw new ArgumentException("Unrecognized file extension: " + ext);
            }
        }

        [TemplateTag]
        public static string favicon(AttrDict attrs, string content)
        {
            return Html.Tag("link", new AttrDict {
                    {"rel", "shortcut icon"},
                    {"type", "image/x-icon"},
                    {"href", content},
                }.Merge(attrs), null);
        }

        [TemplateTag]
        public static string javascript(AttrDict attrs, string content)
        {
            return Html.Tag("script", new AttrDict {
                    {"type", "text/javascript"},
                }.Merge(attrs), content);
        }

        [TemplateTag]
        public static string css(AttrDict attrs, string content)
        {
            return Html.Tag("style", new AttrDict {
                    {"type", "text/css"},
                }.Merge(attrs), content);
        }
    }
}
